import 'package:json_annotation/json_annotation.dart';

part 'ai_ans.g.dart';

@JsonSerializable()
class AiAns {
  @JsonKey(defaultValue: '')
  final String id;
  @JsonKey(defaultValue: '')
  final String object;
  @JsonKey(defaultValue: 0)
  final int created;
  @JsonKey(defaultValue: '')
  final String model;
  final Usage? usage;
  @JsonKey(defaultValue: [])
  final List<Choices> choices;

  AiAns({
    required this.id,
    required this.object,
    required this.created,
    required this.model,
    this.usage,
    required this.choices,
  });

  factory AiAns.fromJson(Map<String, dynamic> json) =>
      _$AiAnsFromJson(json);

  Map<String, dynamic> toJson() => _$AiAnsToJson(this);
}

@JsonSerializable()
class Usage {
  @JsonKey(name: 'prompt_tokens', defaultValue: 0)
  final int promptTokens;
  @JsonKey(name: 'completion_tokens', defaultValue: 0)
  final int completionTokens;
  @JsonKey(name: 'total_tokens', defaultValue: 0)
  final int totalTokens;

  Usage({
    required this.promptTokens,
    required this.completionTokens,
    required this.totalTokens,
  });

  factory Usage.fromJson(Map<String, dynamic> json) =>
      _$UsageFromJson(json);

  Map<String, dynamic> toJson() => _$UsageToJson(this);
}

@JsonSerializable()
class Choices {
  final Message? message;
  @JsonKey(name: 'finish_reason', defaultValue: '')
  final String finishReason;
  @JsonKey(defaultValue: 0)
  final int index;

  Choices({
    this.message,
    required this.finishReason,
    required this.index,
  });

  factory Choices.fromJson(Map<String, dynamic> json) =>
      _$ChoicesFromJson(json);

  Map<String, dynamic> toJson() => _$ChoicesToJson(this);
}

@JsonSerializable()
class Message {
  @JsonKey(defaultValue: '')
  final String role;
  @JsonKey(defaultValue: '')
  final String content;

  Message({
    required this.role,
    required this.content,
  });

  factory Message.fromJson(Map<String, dynamic> json) =>
      _$MessageFromJson(json);

  Map<String, dynamic> toJson() => _$MessageToJson(this);
}
